package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDTO;
import com.heima.model.admin.pojo.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author by jojo
 * @Date 2022/2/25
 * @Description
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理API",tags = "频道管理API")
public class AdChannelController {
    /**
     * 根据名称分页查询频道列表
     */
    @Autowired
    private AdChannelService adChannelService;

    @PostMapping("/list")
    @ApiOperation("频道分页列表查询")
    public ResponseResult<List<AdChannel>> findByNameAndPage(@RequestBody ChannelDTO dto){
        return adChannelService.findByNameAndPage(dto);
    }

    @PostMapping("/save")
    @ApiOperation("频道新增")
    public ResponseResult addChannel(@RequestBody AdChannel channel){
        return adChannelService.addChannel(channel);
    }

    @PostMapping("/update")
    @ApiOperation("频道修改,频道有效无效设置")
    public ResponseResult updateChannel(@RequestBody AdChannel channel){
        return adChannelService.updateChannel(channel);
    }

    @GetMapping("/del/{id}")
    @ApiOperation("根据频道id删除")
    public ResponseResult deleteById(@PathVariable("id") Long id){
        return adChannelService.deleteById(id);
    }

    @GetMapping("/channels")
    public ResponseResult findByAll(){
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }
    @GetMapping("/one/{id}")
    public ResponseResult getByChannel(@PathVariable("id") Integer id){
        AdChannel adChannel = adChannelService.getById(id);
        return ResponseResult.okResult(adChannel);
    }
}
